﻿using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;
//using System.Web.UI;
//using System.Web.UI.WebControls;
//using CrystalDecisions.CrystalReports.Engine;
//using System.IO;
//using System.Configuration;

public partial class reports_viewreport : System.Web.UI.Page
{
    //ReportDocument rd1, rd2;

    //protected void Page_Load(object sender, EventArgs e)
    //{
    //    //if (Session["user"] == null) Response.Redirect("~/Logout.aspx");
    //    //PDFExport();
    //}

    //protected void Page_Init(object sender, EventArgs e)
    //{
    //    string qSQL = "";
    //    string ReportName = "";
    //    string Hdr01 = "";
    //    string Hdr02 = "";
    //    string Hdr03 = "";
    //    string Hdr04 = "";
    //    string Hdr05 = "";
    //    string Hdr06 = "";
    //    string HdrPeriode = "";

    //    //if (Session["ReportName"] != null) ReportName = Session["ReportName"].ToString();
    //    //if (Session["Hdr01"] != null) Hdr01 = Session["Hdr01"].ToString();
    //    //if (Session["Hdr02"] != null) Hdr02 = Session["Hdr02"].ToString();
    //    //if (Session["Hdr03"] != null) Hdr03 = Session["Hdr03"].ToString();
    //    //if (Session["Hdr04"] != null) Hdr04 = Session["Hdr04"].ToString();
    //    //if (Session["Hdr05"] != null) Hdr05 = Session["Hdr05"].ToString();
    //    //if (Session["Hdr06"] != null) Hdr06 = Session["Hdr06"].ToString();
    //    //if (Session["HdrPeriode"] != null) HdrPeriode = Session["HdrPeriode"].ToString();
    //    //if (Session["qSQL"] != null) qSQL = Session["qSQL"].ToString();

    //    string serverdir = "";
    //    serverdir = Server.MapPath("") + "\\";

    //    rd1 = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

    //    rd1.Load(Server.MapPath("~/reportviewer/testlagi.rpt"));// serverdir + ReportName);
    //    //rd1.RecordSelectionFormula = qSQL;

    //    string sConn = ConfigurationManager.AppSettings["DBSetting1"].ToString();

    //    string[] temp = sConn.Split(';');
    //    string username = "sa";// string.Empty;
    //    string password = "Multi123";//string.Empty;
    //    string servername = "nestle";// string.Empty;
    //    string dbname = "kpireport"; //string.Empty;

    //    //foreach (string str in temp)
    //    //{
    //    //    if (str.Contains("server"))
    //    //        servername = str.Split('=')[1];
    //    //    else if (str.Contains("database"))
    //    //        dbname = str.Split('=')[1];
    //    //    else if (str.Contains("uid"))
    //    //        username = str.Split('=')[1];
    //    //    else if (str.Contains("pwd"))
    //    //        password = str.Split('=')[1];
    //    //}

    //    rd1.SetDatabaseLogon(username, password, servername, dbname);

    //    foreach (CrystalDecisions.CrystalReports.Engine.Table myTable in rd1.Database.Tables)
    //    {
    //        int ErrorFunc = 0;
    //        if (ErrorFunc == 0)
    //        {
    //            CrystalDecisions.Shared.TableLogOnInfo myLogin = myTable.LogOnInfo;
    //            myLogin.ConnectionInfo.ServerName = servername;
    //            myLogin.ConnectionInfo.DatabaseName = dbname;
    //            myLogin.ConnectionInfo.UserID = username;
    //            myLogin.ConnectionInfo.Password = password;
    //            myTable.ApplyLogOnInfo(myLogin);
    //        }
    //    }

    //    //CrystalDecisions.CrystalReports.Engine.FormulaFieldDefinition ffd;
    //    //CrystalDecisions.CrystalReports.Engine.FormulaFieldDefinitions ffds;

    //    //ffds = rd1.DataDefinition.FormulaFields;

    //    //ffd = ffds["Hdr01"];
    //    //ffd.Text = Hdr01;
    //    //ffd = ffds["Hdr02"];
    //    //ffd.Text = Hdr02;
    //    //ffd = ffds["Hdr03"];
    //    //ffd.Text = Hdr03;
    //    //ffd = ffds["Hdr04"];
    //    //ffd.Text = Hdr04;
    //    //ffd = ffds["Hdr05"];
    //    //ffd.Text = Hdr05;
    //    //ffd = ffds["Hdr06"];
    //    //ffd.Text = Hdr06;

    //    //// eone-Feb 26, 2009 (Error)
    //    ////try
    //    ////{
    //    ////    if ((ffds["HdrPeriode"] != null) && (Session["HdrPeriode"] != null))
    //    ////    {
    //    ////        ffd = ffds["HdrPeriode"];
    //    ////        ffd.Text = Session["HdrPeriode"].ToString();
    //    ////    }
    //    ////}
    //    ////catch { }

    //    //// Declare a subreport object.
    //    //CrystalDecisions.CrystalReports.Engine.SubreportObject subobj;
    //    //foreach (CrystalDecisions.CrystalReports.Engine.ReportObject obj in rd1.ReportDefinition.ReportObjects)
    //    //{
    //    //    if (obj.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
    //    //    {
    //    //        subobj = (CrystalDecisions.CrystalReports.Engine.SubreportObject)obj;
    //    //        rd2 = rd1.OpenSubreport(subobj.SubreportName);
    //    //        rd2.SetDatabaseLogon(username, password, servername, dbname);

    //    //        foreach (CrystalDecisions.CrystalReports.Engine.Table myTable2 in rd2.Database.Tables)
    //    //        {
    //    //            CrystalDecisions.Shared.TableLogOnInfo myLogin2 = myTable2.LogOnInfo;
    //    //            myLogin2.ConnectionInfo.ServerName = servername;
    //    //            myLogin2.ConnectionInfo.DatabaseName = dbname;
    //    //            myLogin2.ConnectionInfo.UserID = username;
    //    //            myLogin2.ConnectionInfo.Password = password;
    //    //            myTable2.ApplyLogOnInfo(myLogin2);
    //    //        }
    //    //    }
    //    //}

    //    crViewer.ReportSource = rd1;

    //    //rd1.ExportToDisk(ExportFormatType.WordForWindows, serverdir = Server.MapPath("report/report_documents/") + Hdr03 + ".doc");
    //}

    ///// <summary>
    ///// Export Report to PDF
    ///// </summary>
    //protected void PDFExport()
    //{
    //    MemoryStream oStream = new MemoryStream();
    //    oStream = (MemoryStream)rd1.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    //    Response.Clear();
    //    //Response.AddHeader("Content-Disposition", "attachment; filename = MyReport.Pdf");
    //    Response.AddHeader("Content-Disposition", "");
    //    Response.ContentType = "application/pdf";

    //    try
    //    {
    //        Response.BinaryWrite(oStream.ToArray());
    //        Response.End();
    //    }
    //    catch (Exception err)
    //    {
    //        Response.Write(err.Message.ToString());
    //    }
    //}

    //private void ExportToExcel(string strFileName, DataGrid dg)
    //{
    //    Response.Clear();
    //    Response.Buffer = true;
    //    Response.ContentType = "application/vnd.ms-excel";
    //    Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
    //    Response.Charset = "";
    //    this.EnableViewState = false;
    //    System.IO.StringWriter sw = new StringWriter();
    //    System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(sw);
    //    dg.RenderControl(htw);
    //    Response.Write(sw.ToString());
    //    Response.End();
    //}
}